package com.magilit.framelibrary.base;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.magilit.framelibrary.R;


public abstract class FrameDrawerActivity extends FrameBaseActivity {

    //抽屉布局
    protected DrawerLayout drawer_layout;

    //主要显示的界面  容器
    private FrameLayout mainContentLayout;
    private FrameLayout leftContentLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    @Override
    protected void initContentView() {
        setContentView(R.layout.activity_frame_drawer);
        mainContentLayout = (FrameLayout) findViewById(R.id.main_content);
        leftContentLayout = (FrameLayout) findViewById(R.id.left_content);
        drawer_layout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer_layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        drawer_layout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {

            }

            @Override
            public void onDrawerOpened(View drawerView) {
                drawer_layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                drawer_layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });
    }

    /**
     * 代替onCreate的入口类
     */
    protected abstract void onBaseActivityCreated(Bundle savedInstanceState);

    /**
     * 设置Activity中心和侧边栏的布局
     *
     * @param mainLayoutResID 资源Id
     */
    protected final void setContentView(int mainLayoutResID, int leftLayoutResID) {
        if (mainContentLayout != null) {
            LayoutInflater.from(this).inflate(mainLayoutResID, mainContentLayout, true);
        }
        if (leftContentLayout != null) {
            LayoutInflater.from(this).inflate(leftLayoutResID, leftContentLayout, true);
        }
        autoInjectViewField();
    }

    protected void openDrawLayout() {
        drawer_layout.openDrawer(Gravity.LEFT);

    }
    protected void closeDrawLayout() {
        drawer_layout.closeDrawer(Gravity.LEFT);

    }

    protected void setOnDrawChangeListener(DrawerLayout.DrawerListener drawerListener) {
        drawer_layout.addDrawerListener(drawerListener);
    }

}
